import request from '@/utils/request'

// 查询评论列表
export function listComments(query) {
  return request({
    url: '/system/comments/list',
    method: 'get',
    params: query
  })
}

// 查询评论详细
export function getComments(id) {
  return request({
    url: '/system/comments/' + id,
    method: 'get'
  })
}

// 新增评论
export function addComments(data) {
  return request({
    url: '/system/comments',
    method: 'post',
    data: data
  })
}

// 修改评论
export function updateComments(data) {
  return request({
    url: '/system/comments',
    method: 'put',
    data: data
  })
}

// 删除评论
export function delComments(id) {
  return request({
    url: '/system/comments/' + id,
    method: 'delete'
  })
}

// ======== 评论管理相关API ========

// 查询评论列表（包含层级结构，排除被屏蔽的评论）
export function listCommentsWithHierarchy(query) {
  return request({
    url: '/system/comments/listWithHierarchy',
    method: 'get',
    params: query
  })
}

// 查询评论列表（排除被屏蔽的评论）
export function listCommentsWithBlacklist(query) {
  return request({
    url: '/system/comments/listWithBlacklist',
    method: 'get',
    params: query
  })
}

// 屏蔽用户的所有评论
export function blockUserComments(userId) {
  return request({
    url: '/system/comments/blockUser/' + userId,
    method: 'post'
  })
}

// 取消屏蔽用户的所有评论
export function unblockUserComments(userId) {
  return request({
    url: '/system/comments/unblockUser/' + userId,
    method: 'post'
  })
}

// 屏蔽单条评论
export function blockComment(commentId) {
  return request({
    url: '/system/comments/block/' + commentId,
    method: 'post'
  })
}

// 取消屏蔽单条评论
export function unblockComment(commentId) {
  return request({
    url: '/system/comments/unblock/' + commentId,
    method: 'post'
  })
}

// 批量屏蔽评论
export function batchBlockComments(commentIds) {
  return request({
    url: '/system/comments/batchBlock',
    method: 'post',
    data: commentIds
  })
}

// 批量启用评论
export function batchEnableComments(commentIds) {
  return request({
    url: '/system/comments/batchEnable',
    method: 'post',
    data: commentIds
  })
}

// 批量删除评论
export function batchDeleteComments(commentIds) {
  return request({
    url: '/system/comments/batchDelete',
    method: 'post',
    data: commentIds
  })
}

// 根据视频ID查询评论（包含层级）
export function getCommentsByVideoId(videoId, query = {}) {
  return request({
    url: `/system/comments/video/${videoId}`,
    method: 'get',
    params: query
  })
}

// 根据用户昵称搜索评论
export function searchCommentsByNickname(nickname, query = {}) {
  return request({
    url: '/system/comments/searchByNickname',
    method: 'get',
    params: {
      nickname: nickname,
      ...query
    }
  })
}

// 获取评论回复列表
export function getCommentReplies(parentId, query = {}) {
  return request({
    url: `/system/comments/replies/${parentId}`,
    method: 'get',
    params: query
  })
}